package com.jishuo.nontax.view.controller;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.util.GTimeUtil;
import com.jishuo.nontax.bean.vo.BankStationVO;
import com.jishuo.nontax.bean.vo.ChargeBillVO;
import com.jishuo.nontax.bean.vo.WaitaffirmVO;
import com.jishuo.nontax.bfc.service.BaseDataService;
import com.jishuo.nontax.bfc.service.ChargeBillService;
import com.jishuo.nontax.bfc.service.WaitaffirmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 退付书
 */
@Slf4j
@Controller
@RequestMapping(value = "/view/waitaffirm", name = "电子票待查")
public class WaitaffirmViewController {

    @Resource
    private WaitaffirmService waitaffirmService;
    @Resource
    private ChargeBillService chargeBillService;
    @Resource
    private BaseDataService baseDataService;


    // 页面文件位置
    private String prefix = "view/";

    @RequestMapping(value = {"rewaitaffirmview", "rewaitaffirmview/{page}"}, name = "退付书首页")
    public String rewaitaffirmview(@PathVariable(required = false) String page) {
        return prefix + ((page == null) ? "rewaitaffirmview" : page);
    }

    @RequestMapping(value = {"rewaitaffirmhandview", "rewaitaffirmhandview/{page}"}, name = "退付书首页")
    public String rewaitaffirmhandview(@PathVariable(required = false) String page) {
        return prefix + ((page == null) ? "rewaitaffirmhandview" : page);
    }

    @RequestMapping(value = {"waitaffirmview", "waitaffirmview/{page}"}, name = "退付书首页")
    public String waitaffirmview(@PathVariable(required = false) String page) {
        return prefix + ((page == null) ? "waitaffirmview" : page);
    }

    @ResponseBody
    @RequestMapping(value={"/queryWaitaffirmData"})
    public BaseResult queryWaitaffirmData(String billnum) {
       return chargeBillService.getChargeBill(billnum);
    }

    @ResponseBody
    @RequestMapping(value={"/regetWaitaffirm"})
    public BaseResult regetWaitaffirm(WaitaffirmVO waitaffirmvo) {
        return waitaffirmService.regetWaitaffirm(waitaffirmvo);
    }

    @RequestMapping(value={"/rewaitaffirmhandviewpa"})
    public String rewaitaffirmhandviewpa(HttpServletRequest request, HttpServletResponse response) {
        request.setAttribute("listPayWay", baseDataService.findPayWayView());
        request.setAttribute("curDate", GTimeUtil.getDateMark());
        return prefix+"rewaitaffirmhandview";
    }

    @ResponseBody
    @RequestMapping(value={"/regetWaitaffirmHandPay"})
    public BaseResult regetWaitaffirmHandPay(@RequestParam Map data,HttpSession session) {
        UserVO user = (UserVO) session.getAttribute("login_user");
        return waitaffirmService.regetWaitaffirmHandPay(data,user);
    }

    /**
     * @author hlp
     * @date 2023/3/29 14:42
     * @Description: 待查收入查询票据
     */
    @ResponseBody
    @RequestMapping(value={"/queryHistWaitaffirmData"})
    public BaseResult queryHistWaitaffirmData(WaitaffirmVO waitaffirmVO) {
        return waitaffirmService.findWaitaffirm(waitaffirmVO);
    }

    @ResponseBody
    @RequestMapping(value={"/saveWaitaffirmData"})
    public BaseResult saveWaitaffirmData(WaitaffirmVO waitaffirmVO,HttpSession session) {
        UserVO user = (UserVO) session.getAttribute("login_user");
        return waitaffirmService.saveWaitaffirmData(waitaffirmVO,user);
    }

    @ResponseBody
    @RequestMapping(value={"/regetWaitaffirmPay"})
    public BaseResult regetWaitaffirmPay(ChargeBillVO chargeBillVO,HttpSession session) {
        UserVO user = (UserVO) session.getAttribute("login_user");
        chargeBillVO.setIncomeway(1);
        chargeBillVO.setAccountcode(chargeBillVO.getAccountcode1());
        chargeBillVO.setBankaffirm(chargeBillVO.getBankaffirm1());
        BankStationVO bankStation = baseDataService.getBankStation(user.getBankStationId());
        chargeBillVO.setBankstation(bankStation.getBankstationcode());
        return chargeBillService.setChargeBillDeposit(chargeBillVO, "");
    }
}
